﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace simulate_control.Basic
{
    #region USING
    using simulate_control.Repositories;
    using simulate_control.Models;
using simulate_control.Helpers;
    #endregion

    public partial class FrmShiftingCursor : Form
    {
        #region VARIABLES
        public EventHandler Handler { get; set; }
        private int dem2 = 80;
        private int dem3 = 0;
        private int dem4 = 40;
        private int dem5 = 20;
        private FrmAdjustZoom frmAdjustZoom;
        private FrmZoom frmZoom;
        #endregion

        #region METHODS
        public FrmShiftingCursor()
        {
            InitializeComponent();
        }

        private void GetZoomVal(object sender, EventArgs e)
        {
            var eventType = (TransferDataEvent)e;
            string[] comp = eventType.Data.Split(new char[] { '#' });
            lbl1.Text = comp[0];
        }

        private void UpdateValue(object sender, EventArgs e)
        {
            var eventType = (TransferDataEvent)e;
            string[] comp = eventType.Data.Split(new char[] { '#' });
            if (comp[0] == "TRUE")
            {
                frmZoom = new FrmZoom();
                frmZoom.Handler += GetZoomVal;
                frmZoom.Show();
            }
            frmAdjustZoom = null;
        }

        private void ShowAdjustZoomFrm()
        {
            frmAdjustZoom = new FrmAdjustZoom();
            frmAdjustZoom.Handler += UpdateValue;
            frmAdjustZoom.Show();
        }

        public void ProcessKeyEvent(KEY keyEvent)
        {
            switch (keyEvent)
            {
                case KEY.MENU:
                    ShowAdjustZoomFrm();
                    break;

                default:
                    if (frmAdjustZoom != null)
                    {
                        frmAdjustZoom.Focus();
                        frmAdjustZoom.ProcessKeyEvent(keyEvent);
                    }
                    else if (frmZoom != null)
                    {
                        frmZoom.Focus();
                        frmZoom.ProcessKeyEvent(keyEvent);
                    }
                    break;
            }
        }

        private void FrmEmpty_Load(object sender, EventArgs e)
        {
            lbl2.Text = dem2.ToString();
            lbl3.Text = "9." + dem3.ToString();
            lbl4.Text = "34" + "\u00b0" + dem4.ToString() + ".000N";
            lbl5.Text = "135" + "\u00b0" + dem5.ToString() + ".000E";
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            dem2++;
            dem3++;
            dem4++;
            dem5++;

            if (dem2 > 82)
            {
                dem2 = 80;
            }

            if (dem3 > 2)
            {
                dem3 = 0;
            }

            if (dem4 > 49)
            {
                dem4 = 40;
            }

            if (dem5 > 22)
            {
                dem5 = 20;
            }

            lbl2.Text = dem2.ToString();
            lbl3.Text = "9." + dem3.ToString();
            lbl4.Text = "34" + "\u00b0" + dem4.ToString() + ".000N";
            lbl5.Text = "135" + "\u00b0" + dem5.ToString() + ".000E";
        }

        private void pnlDimmerAndContrast_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawEllipse(Pens.Red, 220, 95, 10, 10);
            e.Graphics.FillEllipse(new SolidBrush(Color.Red), 220, 95, 10, 10);

            Point[] pt = { new Point(225, 95), new Point(250, 45), new Point(280, 30) };
            e.Graphics.DrawCurve(Pens.Red, pt);
        }
        #endregion
    }
}
